package com.yuezhi.acl.controller;


import com.yuezhi.acl.entity.SysPermission;
import com.yuezhi.acl.service.SysPermissionService;
import com.yuezhi.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author boys
 * @since 2020-12-16
 */
@RestController
@RequestMapping("/admin/acl/permission")
public class SysPermissionController {

    @Autowired
    private SysPermissionService permissionService;

    //查询所有菜单
    @GetMapping
    public R indexAllPermission() {
        List<SysPermission> list =  permissionService.queryAllMenu();
        return R.success().data("children",list);
    }
    //给角色分配权限
    @PostMapping("/doAssign")
    public R doAssign(String roleId,String[] permissionId) {
        permissionService.saveRolePermissionRealtionShip(roleId,permissionId);
        return R.success();
    }

    //根据角色获取菜单
    @GetMapping("toAssign/{roleId}")
    public R toAssign(@PathVariable String roleId) {
        List<SysPermission> list = permissionService.selectAllMenu(roleId);
        return R.success().data("children", list);
    }
}

